/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.website.service.plugins  
 */
package com.apache.website.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.website.entity.Channel;
import com.apache.website.entity.Manuscript;
import com.apache.website.manager.ChannelManager;
import com.apache.website.manager.ManuscriptManager;

/**
 * description:  删除栏目信息
 * @author dyhou 创建时间：2016-7-26  
 */
public class DelChannelInfoPluginImpl implements PluginConnector {

	private ChannelManager channelManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		String channelId = String.valueOf(param.getParams("channelId"));
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		ParamsVo<Channel> vo = new ParamsVo<Channel>();
		if (Validator.isNotNull(channelId)) {
			ParamsVo<Manuscript> mvo = new ParamsVo<Manuscript>();
			mvo.setKey("manuscriptsByChannelId");
			mvo.setInfoId(channelId);
			long count = Long.valueOf(String.valueOf(manuscriptManager.execute(mvo)));
			if (count > 0) {
				entity.setMessage("请先删除此栏目下的稿件");
				return entity;
			}
			vo.setInfoId(channelId);
			boolean mark = channelManager.deleteInfo(vo);
			if (!mark) {
				entity.setMessage("删除失败");
			} else {
				entity.setEntity("true");
				entity.setMessage("删除成功");
			}
		} else {
			entity.setMessage("请选择要删除的栏目！");
		}
		return entity;
	}

	private ManuscriptManager manuscriptManager;

	public void setManuscriptManager(ManuscriptManager manuscriptManager) {
		this.manuscriptManager = manuscriptManager;
	}

	public void setChannelManager(ChannelManager channelManager) {
		this.channelManager = channelManager;
	}

}
